Skip to content

Conversation

@workingjubilee
Copy link
Member

@workingjubilee workingjubilee commented Feb 5, 2025

I don't believe low-level crates like rustc_abi should have to know or care about higher-level concerns like whether the ABI string is stable for users. These implementation details can be made less open to public inspection. This way the code that governs stability is near the code that enforces stability, and compiled together.

It also abstracts away certain error messages instead of constantly repeating them.

A few error messages are simply deleted outright, instead of made uniform, because they are either too dated to be useful or redundant with other diagnostic improvements we could make. These can be pursued in followups: my first concern was making sure there wasn't unnecessary diagnostics-related code in rustc_abi, which is not well-positioned to understand what kind of errors are going to be generated based on how it is used.

r? @ghost

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 5, 2025
@workingjubilee workingjubilee force-pushed the move-abi-versioning-into-ast branch from 55bc9eb to 4e4fa2a Compare February 5, 2025 20:00
@workingjubilee workingjubilee force-pushed the move-abi-versioning-into-ast branch 4 times, most recently from c66f564 to 8ebebd3 Compare February 6, 2025 00:29
@rust-log-analyzer

This comment has been minimized.

@workingjubilee workingjubilee force-pushed the move-abi-versioning-into-ast branch from 8ebebd3 to 901945e Compare February 6, 2025 01:59
@bors
Copy link
Collaborator

bors commented Feb 6, 2025

☔ The latest upstream changes (presumably #136613) made this pull request unmergeable. Please resolve the merge conflicts.

@workingjubilee workingjubilee force-pushed the move-abi-versioning-into-ast branch from 901945e to 2bd2dea Compare February 7, 2025 19:31
@rustbot rustbot added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Feb 7, 2025
@workingjubilee workingjubilee marked this pull request as ready for review February 7, 2025 19:32
@rustbot
Copy link
Collaborator

rustbot commented Feb 7, 2025

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in compiler/rustc_codegen_ssa/src/codegen_attrs.rs

cc @jdonszelmann

These commits modify compiler targets.
(See the Target Tier Policy.)

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@workingjubilee workingjubilee changed the title WIP: compiler: gate extern "{abi}" in ast_lowering compiler: gate extern "{abi}" in ast_lowering Feb 7, 2025
@workingjubilee
Copy link
Member Author

r? @compiler-errors or reroll

@workingjubilee
Copy link
Member Author

I split out the first four commits again into #136706 but that's as far as things can be cut.

@workingjubilee workingjubilee force-pushed the move-abi-versioning-into-ast branch 2 times, most recently from 79d0646 to f5512f4 Compare February 7, 2025 20:24
@bors
Copy link
Collaborator

bors commented Feb 9, 2025

☔ The latest upstream changes (presumably #136762) made this pull request unmergeable. Please resolve the merge conflicts.

@workingjubilee workingjubilee force-pushed the move-abi-versioning-into-ast branch from f5512f4 to 5d7c093 Compare February 9, 2025 18:41
@@ -1,4 +1,4 @@
error[E0658]: intrinsics are subject to change
error[E0658]: rust-intrinsic ABI is an implementation detail and perma-unstable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, what about:

the "rust-intrinsic" ABI is [...]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and similarly for above

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! should it be extern "abi" so it looks like what people actually write in syntax?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed a diff for consideration~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops yep sounds good i was busy watching sportsball

@workingjubilee workingjubilee force-pushed the move-abi-versioning-into-ast branch from 1fcf247 to 6b8fab8 Compare February 10, 2025 00:54
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, i have a few questions but r=me regardless

| help: did you mean: `"riscv-interrupt-m"`
|
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
= note: please use one of riscv-interrupt-m or riscv-interrupt-s for machine- or supervisor-level interrupts, respectively
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where'd this message go? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's functionally redundant with this one:

| help: did you mean: "riscv-interrupt-m"

If there are two suggestions of equal distance and we want to suggest "try either of these", then we should just do that in a generalized way instead.

@@ -1,4 +1,4 @@
error[E0658]: intrinsics are subject to change
error[E0658]: rust-intrinsic ABI is an implementation detail and perma-unstable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops yep sounds good i was busy watching sportsball

@@ -1,4 +0,0 @@
extern "wasm" fn test() {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove this test?

Copy link
Member Author

@workingjubilee workingjubilee Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a suggestion that was for migrating off a nightly feature, starting from last July.

The only users of the feature that I'm aware of are people implementing next-generation wasm toolchain components. So, the people working with us on the migration of wasm's extern "C" to match clang's. They... have known about this for some time, so it seems unlikely they will still benefit from a continued reminder into the future.

So, I removed the suggestion, as we don't usually keep around migration stuff for nightly things for more than a couple of releases, and it's been some. Thus, this test winds up testing nothing.

By moving this stability check into AST lowering, we effectively make
it impossible to accidentally miss, as it must happen to generate HIR.
Also, we put the ABI-stability code next to code that actually uses it!
This allows code that wants to reason about backend ABI implementations
to stop worrying about high-level concerns like syntax stability,
while still leaving it as the authority on what ABIs actually exist.

It also makes it easy to refactor things to have more consistent errors.
For now, we only apply this to generalize the existing messages a bit.
These are either residue of a long-term migration away from something,
or are simply trying too hard to be specifically useful:
nearest-match suggestions for ABI strings should handle this.
@workingjubilee workingjubilee force-pushed the move-abi-versioning-into-ast branch from 6b8fab8 to cd9d39e Compare February 10, 2025 04:52
@workingjubilee
Copy link
Member Author

@bors r=compiler-errors

@bors
Copy link
Collaborator

bors commented Feb 10, 2025

📌 Commit cd9d39e has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 10, 2025
@bors bors merged commit 38f4c1f into rust-lang:master Feb 11, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Feb 11, 2025
@workingjubilee workingjubilee deleted the move-abi-versioning-into-ast branch February 11, 2025 11:00
}
}

pub fn extern_abi_stability(abi: ExternAbi) -> Result<(), UnstableAbi> {
Copy link
Member

@RalfJung RalfJung Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having this in the middle of this huge crate will make it even harder to get "all relevant info fir a given ABI" at a glance. It's a right mess and hard to keep track of: list of ABIs, stability, adjustments, lowering to CallConv, "is this ABI supported" all happen in completely different parts of the codebase.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have that issue for all stability concerns, because we have a really bad organization of how stability checks work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants